package com.gress.shop.dao.impl;

import com.google.common.collect.Lists;
import com.gress.shop.bo.RoleActionRelation;
import com.gress.shop.bo.example.RoleActionRelationExample;
import com.gress.shop.dao.IRoleActionRelationDao;
import com.gress.shop.mapper.RoleActionRelationMapper;
import com.gress.shop.util.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created xiongwen with 2018/4/12 10:15
 * Description:
 */
@Service
public class RoleActionRelationDaoImpl implements IRoleActionRelationDao {

    @Resource
    private RoleActionRelationMapper roleActionRelationMapper;

    @Override
    public int countByExample(RoleActionRelationExample example) {
        return roleActionRelationMapper.countByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(String id) {
        return roleActionRelationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(RoleActionRelation record) {
        String uuid = UUIDUtil.getUUID();
        record.setId(uuid);
        return roleActionRelationMapper.insert(record);
    }

    @Override
    public int insertSelective(RoleActionRelation record) {
        String uuid = UUIDUtil.getUUID();
        record.setId(uuid);
        return roleActionRelationMapper.insertSelective(record);
    }

    @Override
    public List<RoleActionRelation> selectByExample(RoleActionRelationExample example) {
        return roleActionRelationMapper.selectByExample(example);
    }

    @Override
    public RoleActionRelation selectByPrimaryKey(String id) {
        return roleActionRelationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(RoleActionRelation record) {
        return roleActionRelationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(RoleActionRelation record) {
        return roleActionRelationMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<RoleActionRelation> selectByRoleId(String roleId) {
        RoleActionRelationExample example = new RoleActionRelationExample();
        example.createCriteria().
                andRoleIdEqualTo(roleId)
                .andIsValidEqualTo(1);
        List<RoleActionRelation> roleActionRelations = roleActionRelationMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(roleActionRelations)) {
            return Lists.newArrayList();
        }
        return roleActionRelations;
    }

    @Override
    public List<RoleActionRelation> selectAll() {
        RoleActionRelationExample example = new RoleActionRelationExample();
        example.createCriteria()
                .andIsValidEqualTo(1);
        return roleActionRelationMapper.selectByExample(example);
    }
}
